package com.itheima.excel;

import com.alibaba.excel.EasyExcel;
import com.itheima.excel.entity.User;
import com.itheima.excel.listener.DemoDataListener;
import com.itheima.excel.mapper.UserMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ResourceUtils;

import java.io.FileNotFoundException;

@SpringBootTest
public class SimpleRead {

    @Autowired
    UserMapper userMapper;

    @Test
    public void simpleRead3() throws FileNotFoundException {
        String fileName = ResourceUtils.getFile("classpath:excel/demo.xlsx").getAbsolutePath();
        // 有个很重要的点 DemoDataListener 不能被spring管理，要每次读取excel都要new,然后里面用到spring可以构造方法传进去
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(fileName, User.class, new DemoDataListener(userMapper)).sheet().doRead();
    }


}